import 'package:flutter/cupertino.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

import 'SPutil.dart';
import 'Settings.dart';
class JpushUtil{

  JpushUtil._internal();
  factory JpushUtil()=>_instance;
  static final JpushUtil _instance = JpushUtil._internal();
  final JPush jPush = JPush();
  static JpushUtil getInstance(){
    return _instance;
  }

  void init(){
    jPush.addEventHandler(
      onReceiveNotification: (Map<String, dynamic> message) async {
        print("flutter onReceiveNotification: $message");
      },
      onOpenNotification: (Map<String, dynamic> message) async {
        print("flutter onOpenNotification: $message");
      },
      onReceiveMessage: (Map<String, dynamic> message) async {
        print("flutter onReceiveMessage: $message");
      },
      onReceiveNotificationAuthorization: (Map<String, dynamic> message) async {
        print("flutter onReceiveNotificationAuthorization: $message");
      }
    );

    jPush.setup(
      appKey: "0427e04a090ce20e2199f0b0",
      channel: "flutter_channel",
      production: false,
      debug: false,
    );
    jPush.getRegistrationID().then((rid) {
      SPutil.setLocalStorage(Settings.localStorageKeys["推送令牌"],rid );
    });

  }

  Future<String> getRegistrationID()async{
    return await jPush.getRegistrationID();
  }

}